﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Lidgren.Network;

namespace Networking.Packets
{
    public class PlayerInfoPacket
    {

        public const UInt64 TAG = 1;
        public PlayerInfoPacket() { }
        public PlayerInfoPacket(UInt64 playerId, string displayname, int health=-1) : this(0, playerId, displayname, health) { }
        public PlayerInfoPacket(UInt64 senderId, UInt64 playerId, string displayname, int health=-1)
        {
            SenderId = senderId;
            PlayerId = playerId;
            DisplayName = displayname;
            Health = health;
        }
        public UInt64 PlayerId{get;set;}
        public UInt64 SenderId { get; set; }
        public String DisplayName { get; set; }
        public Int32 Health { get; set; }

        public static void BuildOutputMessage(ref NetOutgoingMessage msg, PlayerInfoPacket pack)
        {
            msg.Write(TAG);
            msg.Write(pack.PlayerId);
            msg.Write(pack.DisplayName);
            msg.Write(pack.Health);
        }
        public static void ParseMessage(NetIncomingMessage msg, ref PlayerInfoPacket pack)
        {
            pack.PlayerId = (UInt64)msg.ReadInt64();
            pack.DisplayName = msg.ReadString();
            pack.Health = msg.ReadInt32();
        }
    }
}
